package com.example.controller;

import com.example.common.result.Result;
import com.example.entity.mes.Maintain;
import com.example.service.MaintainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin // 跨域
@RestController
@RequestMapping("/api/Maintain")
@Api(tags = "点检保养项目控制器")
public class MaintainController {

    @Resource
    private MaintainService maintainService;

    @PostMapping("/queryIPageList")
    @ResponseBody
    @ApiOperation("点检保养分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编号", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "type", value = "类型", dataType = "String", dataTypeClass = String.class)
    })
    public Result queryMaintainIPageList(@RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size, String code, String name, String type){
        return this.maintainService.queryMaintainIPageList(current,size,code,name,type);
    }

    @GetMapping("/queryMaintainById/{id}")
    @ResponseBody
    @ApiOperation("通过id进行详细查询")
    public Result queryMaintainById(@PathVariable Long id){
        return this.maintainService.queryMaintainById(id);
    }

    @PostMapping("/insertMaintain")
    @ResponseBody
    @ApiOperation("新增")
    public Result insertMaintain(@RequestBody Maintain maintain){
        return this.maintainService.insertMaintain(maintain);
    }

    @PutMapping("/updateMaintain")
    @ResponseBody
    @ApiOperation("修改")
    public Result updateMaintain(@RequestBody Maintain maintain){
        return this.maintainService.updateMaintain(maintain);
    }

    @DeleteMapping("/deleteMaintain/{id}")
    @ResponseBody
    @ApiOperation("物理删除")
    public Result deleteMaintain(@PathVariable Long id){
        return this.maintainService.deleteMaintain(id);
    }

    @ApiOperation("批量物理删除/也可单物理删除")
    @DeleteMapping("/deleteMaintainBatch/{ids}")
    public Result deleteMaintainBatch(@PathVariable List<Integer> ids) {
        return this.maintainService.deleteMaintainBatch(ids);
    }
}
